﻿using System;
using System.Collections.Generic;
using AbstractBugTracker;
using SmartAssembly;
using Utilities;

namespace Engine.Buggets
{
    internal sealed class BuildRaisedOn<TBug> : IBugget<TBug>
        where TBug : class, IBug
    {
        public IEnumerable<Tuple<ProcessedReport, TBug>> Run(ProcessedReport processedReport, TBug bug)
        {
            Version thisBuild = processedReport.ProductBuildRef.ProductBuildVersion;

            Version earliestBuild = bug.EarliestBuild;
            if (earliestBuild == null || thisBuild < earliestBuild)
            {
                bug.EarliestBuild = thisBuild;
            }

            Version latestBuild = bug.LatestBuild;
            if (latestBuild == null || thisBuild > latestBuild)
            {
                bug.LatestBuild = thisBuild;
            }

            yield return new Tuple<ProcessedReport, TBug>(processedReport, bug);
        }
    }
}
